import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.List;


public class RedisDemoString {
    public static void test1(Jedis jedis) {
        System.out.println("mget 和 mset");
        jedis.flushAll();
        jedis.mset("key1", "111", "key2", "222","key3", "333");
        List<String> values = jedis.mget("key1", "key2","key3");
        System.out.println(values);
    }
    public static void test2(Jedis jedis) {
        System.out.println("getrange 和 setrange");
        jedis.flushAll();
        jedis.set("key","abcdefghijklmn");;
        String result = jedis.getrange("key",0,-1);
        System.out.println(result);

        jedis.setrange("key",3,"我的发");//redis中一个汉字三个字节
        result = jedis.getrange("key",0,-1);
        System.out.println(result);
    }
    public static void test3(Jedis jedis) {
        System.out.println("append:");
        jedis.flushAll();
        jedis.set("key","kzf");
        jedis.append("key"," love whx");
        String value= jedis.get("key");
        System.out.println(value);

    }
    public static void test4(Jedis jedis) {
        System.out.println("incr 和 decr");
        jedis.flushAll();
        jedis.set("key","222");
        System.out.println(jedis.get("key"));
        long result=jedis.incr("key");
        System.out.println(result);
        result = jedis.decr("key");
        System.out.println(result);
    }
    public static void main(String[] args) {
        JedisPool jedisPool = new JedisPool("127.0.0.1", 8888);
        try (Jedis jedis = jedisPool.getResource()) {
            test4(jedis);
        }
    }
}
